#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

#include<time.h>
#define FLNAME "log"
#define BUFFSZ 1024
int main(void)
{
	FILE *fp;
	int count=0;
	char buff[BUFFSZ];
	time_t stamp;
	struct tm *tm;
	fp=fopen(FLNAME,"a+");

	if(fp==NULL)
	{
		perror("open");
		return 1;
	}
	while(fgets(buff,BUFFSZ,fp)!=NULL)
		count++;
	
	while(1)
	{
		time(&stamp);
		tm=localtime(&stamp);
		fprintf(fp,"%-6d  %d-%d-%d  %d:%d:%d\n",++count,tm->tm_year+1900,1+tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
		sleep(1);
	fflush(fp);
	}
	fclose(fp);


	return 0;
}

